//
//  ViewController.m
//  tangshantongjiAPP
//
//  Created by yuntai on 2018/4/2.
//  Copyright © 2018年 yuntai. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *usernameview;
@property (weak, nonatomic) IBOutlet UIView *passWordView;
@property (weak, nonatomic) IBOutlet UITextField *nameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passWordTextField;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    UIGraphicsBeginImageContextWithOptions(self.usernameview.bounds.size, NO, 1.0);
//    UIBezierPath *path =[UIBezierPath bezierPathWithRoundedRect:self.usernameview.bounds cornerRadius:5];
//    CAShapeLayer *layer = [CAShapeLayer layer];
//    layer.frame = self.usernameview.bounds;
//    layer.path = path.CGPath;
//    [self.usernameview.layer addSublayer:layer];
//    UIGraphicsEndImageContext();
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenBoundWidth,   kNavigationHeight-44)];
    topView.backgroundColor = kNavigationColor;
    [self.view addSubview:topView];
    
    self.usernameview.layer.cornerRadius = 5.f;
    self.usernameview.layer.masksToBounds = YES;
    
    self.passWordView.layer.cornerRadius = 5.f;
    self.passWordView.layer.masksToBounds = YES;
    


    
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if (kUserLoginName) {
        self.nameTextField.text = kUserLoginName?:@"";
        if (kUserLoginPassword) {
            self.passWordTextField.text = kUserLoginPassword?:@"";
        }
    }
}
- (IBAction)tapAction:(UITapGestureRecognizer *)sender {
    [self.view endEditing:YES];
}
- (IBAction)loginBtnAction:(UIButton *)sender {
    [self.view endEditing:YES];
    [self loginAction];

}

- (void)loginAction{
    if (self.nameTextField.text.length == 0 ) {
        [HUDManager showWarningWithText:@"请输入用户名"];
        return;
    }
    if (self.passWordTextField.text.length == 0 ) {
        [HUDManager showWarningWithText:@"请输入密码"];
        return;
    }
    [HUDManager showLoadingHUDView: self.view];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:self.nameTextField.text?:@"" forKey:@"userName"];
    [params setValue:self.passWordTextField.text?:@"" forKey:@"password"];

    [NetWork PostNetWorkWithUrl:kUserLoginAction with:params successBlock:^(NSDictionary *dic) {
        
        
        
        [kUserDefault setObject:self.passWordTextField.text forKey:kVersionLoginPassword];
        [kUserDefault synchronize];
        
        [[UserAccountManager shareUserAccountManager] loginWithUserDic:dic[@"data"]];
        
       

        
    } FailureBlock:^(NSString *msg) {
        [HUDManager showWarningWithText:msg];
    } errorBlock:^(id error) {
        
    }];
}

@end
